import 'dart:io';

import 'package:base_moudle/index.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/services.dart';
import 'package:flutter_easyloading/flutter_easyloading.dart';
import 'package:flutter_module/new_paltform/widgets/management/drawing/list/hy_drawing_management_page.dart';
import 'package:flutter_module/new_paltform/widgets/management/meeting/list/hy_metting_management_page.dart';
import 'package:flutter_spinkit/flutter_spinkit.dart';

import '../../../config/zs_routers.dart';
import '../../../feature_approval/index.dart';
import '../../../feature_daily_work/zs_asso_problems/zs_problems_list/zs_problems_view.dart';
import '../../../models/data_model/HyWorkModel.dart';
import '../../../new_paltform/define/hy_header.dart';
import '../../../new_paltform/widgets/litigation_case/litigation_case_view.dart';
import '../../../new_paltform/widgets/project_contract_management/xm_contract_management_view.dart';
import '../../../new_paltform/widgets/project_investment_management/xm_investment_management_view.dart';
import '../../../new_paltform/widgets/project_personnel/project_personnel_view.dart';
import '../../../new_paltform/widgets/project_progress_control/xm_progress_control_view.dart';
import '../../../new_paltform/widgets/work_barometer/work_project_barometer_page.dart';
import '../../../new_paltform/widgets/work_offline/hy_work_offline_list_page.dart';
import '../../../new_paltform/widgets/work_project_announcement/work_project_announcement_list_view.dart';
import '../../../webview/hy_in_app_webiew.dart';
import '../../command/project/zs_command_data/view.dart';
import '../../other/rebar_detection/rebar_detection_page.dart';
import '../../work/work_state/work_state_page.dart';
import '../../work/zs_change_project/zs_change_project_view.dart';
import '../../work/zs_mine_audit_list/zs_mine_audit_view.dart';
import '../../work/zs_project_cotasking/zs_cotasking_list_view.dart';
import '../../work/zs_project_unit_construction/zs_project_unit_construction_view.dart';
import '../../work/zs_self_checking/zs_correction_notice/zs_correction_notice_view.dart';
import '../../work/zs_self_checking/zs_penalty_notice/zs_penalty_notice_view.dart';
import '../../work/zs_self_checking/zs_project_self_checking/zs_checking_view.dart';
import '../../work/zs_task/zs_task_list/zs_more_task_view.dart';
import '../../work/zs_task/zs_task_part_list/zs_task_part_list.dart';
import '../../work/zs_work_attendance/zs_clockin_tongji.dart';
import '../../work/zs_work_customer_management/view.dart';
import '../../work/zs_work_log_manage/zs_work_log_home_view.dart';
import '../../work/zs_work_signature/zs_signature_view.dart';
import '../../work/zs_work_space/zs_work_document_center/zs_work_document_center_view.dart';
import '../db/work_app_model.dart';
import '../setting/work_setting.dart';
import 'add_often_used/hy_add_often_used_page.dart';
import 'add_often_used/popup_menu_button/popup_menu_util.dart';
import 'add_often_used/popup_menu_button/tap_item.dart';
import 'cell/hy_notice_cell.dart';
import 'cell/hy_project_top_cell.dart';
import 'drawer/hy_work_store_drawer_page.dart';
import 'hy_work_app_button.dart';
import 'hy_work_home_logic.dart';

class HYWorkbenchDetailPage extends StatefulWidget {
  HYWorkbenchDetailPage();

  @override
  _HYWorkbenchDetailPageState createState() => _HYWorkbenchDetailPageState();
}

class _HYWorkbenchDetailPageState extends State<HYWorkbenchDetailPage>
    with AutomaticKeepAliveClientMixin, SingleTickerProviderStateMixin {
  RxDouble rx_height = (Get.height * 0.5).obs;

  List<String> appsTypes = ItemModel.appTypes();
  HyWorkHomeLogic controller = Get.put(HyWorkHomeLogic());
  late TabController _tabController;
  ScrollController? scrollController;

  void initData() {
    _tabController = TabController(vsync: this, length: appsTypes.length);
  }

  @override
  Widget build(BuildContext context) {
    return Obx(() => PageViewBase(
          status: controller.workStatus.value,
          backgroundColor: Colors.white,
          onRetry: () {
            controller.pageStatus.value = PageStatus.loading;
            controller.loginWork();
          },
          body: RfListView(
            enablePullUp: false,
            itemCount: 4,
            controller: scrollController,
            indexedWidgetBuilder: (BuildContext c, int i) {
              if (i == 0) {
                return _buildIntroduceCell();
              } else if (i == 1) {
                return _buildProjectIntroduceCell();
              } else if (i == 2) {
                return _notice();
              } else {
                return Obx(() => _buildAllApp());
              }
            },
          ),
        ));
  }

  Widget placeholder() {
    return zs_round_radius_contianer(
        margin: const EdgeInsets.all(15),
        padding: const EdgeInsets.all(15),
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            const SpinKitThreeBounce(
              color: Colors.black26,
            ),
            Center(
              child: ZsText('数据加载中'),
            )
          ],
        ).paddingOnly(top: 80, bottom: 80));
  }

  Widget _buildIntroduceCell() {
    return _buildTitleView(
        title: '我的常用',
        rightChildr: Row(
          children: [
            HYButton.icon(
              icon: Image.asset(
                'assets/images/project/work_add.png',
                width: 20,
                height: 20,
              ),
              title: '添加',
              textColor: ColorHex('#207EFA'),
              fontWeight: FontWeight.bold,
              fontSize: 16,
              gap: 0,
              onPressed: () {
                routeNative('添加');
              },
            ).marginOnly(right: 10),
            HYButton.icon(
              icon: Image.asset(
                'assets/images/project/work_manage.png',
                width: 20,
                height: 20,
              ),
              title: '管理',
              textColor: ColorHex('#207EFA'),
              fontWeight: FontWeight.bold,
              fontSize: 16,
              gap: 0,
              onPressed: () {
                routeNative('管理');
              },
            ),
          ],
        ),
        childr: Obx(() => _buildItemsCell(
              itemModelList: controller.itemList,
              longBool: true,
            )));
  }

  Widget _buildItemsCell(
      {required List<ItemModel> itemModelList,
      bool isSelect = true,
      bool longBool = false}) {
    if (longBool == false && itemModelList.isEmpty) {
      return Column(
        children: [
          Image.asset(
            'assets/images/empty_data.png',
            height: 200,
            fit: BoxFit.cover,
          ),
          ZsText(
            '暂无数据',
            textAlign: TextAlign.center,
            color: zs_color_ccc,
            bottom: 20,
          )
        ],
      );
    }
    if (longBool == false) {
      final int count = (itemModelList.length / 4).ceil();
      final double h = (Get.width - 30) / (4 * 0.78);
      final double newHeight = h * count + (count - 1) * 10 + 20 + 60;
      if (newHeight > rx_height.value) {
        rx_height.value = newHeight;
      }
    }

    return Container(
      padding: EdgeInsets.zero,
      child: GridView.builder(
        gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
            crossAxisCount: 4,
            crossAxisSpacing: 10,
            childAspectRatio: 0.78,
            mainAxisSpacing: 10),
        physics: const NeverScrollableScrollPhysics(),
        //增加
        shrinkWrap: true,
        //增加
        itemCount: isSelect ? itemModelList.length + 1 : itemModelList.length,
        itemBuilder: (BuildContext ctx, int index) {
          if (index == itemModelList.length) {
            return Column(
              children: [
                Image.asset(
                  'assets/images/project/work_add_app.png',
                  fit: BoxFit.fitWidth,
                ).intoContainer(
                    height: size_wh,
                    width: size_wh,
                    margin: const EdgeInsets.only(top: 10, bottom: 10)),
                ZsText(
                  '添加常用',
                  textAlign: TextAlign.center,
                  fontSize: 13,
                  maxLines: 1,
                )
              ],
            ).intoGestureDetector(onTap: () {
              routeNative('添加常用');
            });
          } else {
            final ItemModel model = itemModelList[index];
            return buildGardViewItem(model, longBool);
          }
        },
      ),
    );
  }

  Widget buildGardViewItem(ItemModel model, bool longBool) {
    ItemModel element = model;
    int number = 0;
    if (model.type == 'web') {
      final item = controller.webList.where((e) => e.title == model.title);
      if (item.isNotEmpty) {
        element = item.first;
      }
      number = element.number ?? 0;
    } else if (model.type == '办公工作' && model.title == '我的邮件') {
      number = controller.emailCount.value;
    }

    if (longBool == true) {
      return LayoutBuilder(
        builder: (BuildContext p0, BoxConstraints p1) {
          return GestureDetector(
            behavior: HitTestBehavior.opaque,
            onLongPressStart: (LongPressStartDetails details) async {
              HapticFeedback.mediumImpact();
              await PopupMenuUtil.showPopupMenu(context, details, p1, [
                TapItem(
                  img: 'assets/images/project/project_remove.png',
                  text: '移除',
                  onTap: () {
                    controller.itemList.remove(model);
                    controller.onUpdateLike();
                  },
                ),
                TapItem(
                  img: 'assets/images/project/project_sort.png',
                  text: '排序',
                  onTap: () {
                    routeNative('管理');
                  },
                )
              ]);
            },
            child: HyWorkAppImageButton(
              buttomItem: element,
              number: number,
              onPressed: () {
                //注释：单击处理
                print('单击处理');
                if (model.type == 'web') {
                  if (element.appUrl == '') {
                    Get.toNamed(ZsRouter.zsWorkFunctionSecond,
                        arguments: {
                          'title': element.title,
                          'fatherId': element.menuId
                        },
                        preventDuplicates: false);
                  } else if (element.appUrl?.startsWith('/future') ?? false) {
                    //跳转原生
                    if (element.appUrl == '/future') {
                      routeNative(model.title);
                    } else {
                      try {
                        Get.toNamed(element.appUrl!);
                      } catch (e) {
                        routeNative(model.title);
                      }
                    }
                  } else if (element.appUrl?.startsWith('key_') ?? false) {
                    final String str = element.appUrl!.replaceAll('key_', '');
                    routeNative(str, name: element.title);
                  } else {
                    String url =
                        '${ZsMemeryCache.zsWorkLoginModel!.workPath}/${element.appUrl!}&userId=${ZsMemeryCache.zsWorkLoginModel?.workModuleUserId}&view=${ZsMemeryCache.loginDataModel!.userInfo!.userName}&uid=${ZsMemeryCache.loginDataModel!.userInfo!.encryptionPassword!.toString()}';
                    url = Uri.encodeFull(url);
                    Get.to(HYInAppWebViewPage(
                      url: url,
                      showAppbar: false,
                    ));
                  }
                } else {
                  routeNative(model.title);
                }

                HyWorkAppModel.saveClickModel(model: model)
                    .whenComplete(() => controller.onTimeList());
              },
            ),
          );
        },
      );
    } else {
      return HyWorkAppImageButton(
        buttomItem: element,
        number: number,
        onPressed: () {
          //注释：单击处理
          print('单击处理');
          if (model.type == 'web') {
            if (element.appUrl == '') {
              Get.toNamed(ZsRouter.zsWorkFunctionSecond,
                  arguments: {
                    'title': element.title,
                    'fatherId': element.menuId
                  },
                  preventDuplicates: false);
            } else if (element.appUrl?.startsWith('/future') ?? false) {
              //跳转原生
              if (element.appUrl == '/future') {
                routeNative(model.title);
              } else {
                try {
                  Get.toNamed(element.appUrl!);
                } catch (e) {
                  routeNative(model.title);
                }
              }
            } else if (element.appUrl?.startsWith('key_') ?? false) {
              final String str = element.appUrl!.replaceAll('key_', '');
              routeNative(str, name: element.title);
            } else {
              String url =
                  '${ZsMemeryCache.zsWorkLoginModel!.workPath}/${element.appUrl!}&userId=${ZsMemeryCache.zsWorkLoginModel?.workModuleUserId}&view=${ZsMemeryCache.loginDataModel!.userInfo!.userName}&uid=${ZsMemeryCache.loginDataModel!.userInfo!.encryptionPassword!.toString()}';
              url = Uri.encodeFull(url);
              Get.to(HYInAppWebViewPage(
                url: url,
                showAppbar: false,
              ));
            }
          } else {
            routeNative(model.title);
          }

          HyWorkAppModel.saveClickModel(model: model)
              .whenComplete(() => controller.onTimeList());
        },
      );
    }
  }

  Widget _notice() {
    return Obx(() {
      if (controller.noticeList.isNotEmpty) {
        return HyNoticeCell(controller: controller);
      } else {
        return Container();
      }
    });
  }

  Widget _buildAllApp() {
    return HYContainer(
      child: Column(
        children: [
          ZsText(
            '全部应用',
            fontSize: 18,
            fontWeight: FontWeight.bold,
          ).intoContainer(
              alignment: Alignment.centerLeft,
              padding: const EdgeInsets.only(top: 32, left: 16, bottom: 6)),
          DefaultTabController(
            length: appsTypes.length,
            child: Column(
              children: [
                HYContainer(
                  alignment: Alignment.centerLeft,
                  border: Border(bottom: BorderSide(color: zs_color_f2)),
                  padding: const EdgeInsets.only(right: 16),
                  child: Stack(
                    alignment: Alignment.center,
                    children: [
                      TabBar(
                        labelColor: zs_mainColor,
                        labelStyle: const TextStyle(
                            fontSize: 14, fontWeight: FontWeight.bold),
                        unselectedLabelStyle: const TextStyle(fontSize: 14),
                        unselectedLabelColor: zs_black_333,
                        indicatorSize: TabBarIndicatorSize.label,
                        indicatorColor: zs_mainColor,
                        overlayColor:
                            MaterialStateProperty.all(Colors.transparent),
                        isScrollable: true,
                        controller: _tabController,
                        tabs: appsTypes
                            .map((String e) => Tab(
                                  text: e,
                                ))
                            .toList(),
                      ).marginOnly(right: 45),
                      Align(
                        alignment: Alignment.centerRight,
                        child: HYContainer(
                          padding: const EdgeInsets.fromLTRB(5, 5, 0, 5),
                          child: Image.asset(
                            'assets/images/project/work_store.png',
                            width: 18,
                            height: 14,
                          ),
                          onTap: () {
                            HyWorkStoreDrawerPage.push(
                                    arr: appsTypes,
                                    context: context,
                                    seleted: _tabController.index)
                                ?.then((String? value) {
                              if (value != null) {
                                final int selectIndex =
                                    appsTypes.indexOf(value);
                                _tabController.animateTo(selectIndex);
                              }
                            });
                          },
                        ),
                      ),
                    ],
                  ),
                ),
                Expanded(
                    child: TabBarView(
                        controller: _tabController,
                        children: appsTypes
                            .map((String e) => _buildTabBarView(e))
                            .toList()))
              ],
            ),
          ).intoContainer(height: rx_height.value),
        ],
      ),
    );
  }

  Widget _buildTabBarView(String str) {
    List<ItemModel> list = [];
    if (str == '最近使用') {
      list = controller.timeList;
    } else if (str == '办公工作') {
      list = controller.allList
          .where((ItemModel element) => ['办公工作', 'web'].contains(element.type))
          .toList();
    } else {
      list = controller.allList
          .where((ItemModel element) => element.type == str)
          .toList();
    }

    return SingleChildScrollView(
      child: _buildItemsCell(itemModelList: list, isSelect: false),
    ).marginOnly(top: 10, left: 15, right: 15);
  }

  Widget _buildProjectIntroduceCell() {
    return Obx(() {
      if (controller.canNew.value) {
        return _buildTitleView(
          title: '当前项目',
          rightChildr: Row(
            children: [
              HYButton.icon(
                icon: Image.asset(
                  'assets/images/project/work_switch.png',
                  width: 20,
                  height: 20,
                ),
                title: '切换项目',
                textColor: ColorHex('#207EFA'),
                fontWeight: FontWeight.bold,
                fontSize: 16,
                gap: 0,
                onPressed: () {
                  Get.to(() => ZsChangeProjectPage(
                      controller.projectDetail.value.pid!))?.then((value) {
                    if (value is String) {
                      controller.canNew.value = false;
                      controller.projectId = value;
                      controller.requestProjectDetail();
                    }
                  });
                },
              ).marginOnly(right: 16),
              Obx(() {
                String iconName =
                    'assets/images/project/work_manage_unfold.png';
                String title = '展开';
                if (controller.isOpenMore.value) {
                  iconName = 'assets/images/project/work_manage_ contract.png';
                  title = '收起';
                }
                return HYButton.icon(
                  icon: Image.asset(
                    iconName,
                    width: 20,
                    height: 20,
                  ),
                  title: title,
                  textColor: ColorHex('#207EFA'),
                  fontWeight: FontWeight.bold,
                  fontSize: 16,
                  gap: 0,
                  onPressed: () {
                    if (controller.isOpenMore.value) {
                      scrollController?.jumpTo(10);
                    }
                    controller.isOpenMore.value = !controller.isOpenMore.value;
                  },
                );
              }),
            ],
          ),
          childr: HyProjectTopCell(
            controller: controller,
            scrollController: scrollController,
          ).marginOnly(top: 20, bottom: 16),
        );
      } else {
        return Container();
      }
    });
  }

  Widget _buildTitleView({
    required String title,
    required Widget rightChildr,
    required Widget childr,
    double top = 32,
    double right = 16,
    double left = 16,
    double bottom = 0,
  }) {
    return HYContainer(
      padding: EdgeInsets.fromLTRB(left, top, right, bottom),
      backgroundColor: Colors.white,
      child: Column(
        children: [
          Row(
            mainAxisAlignment: MainAxisAlignment.spaceBetween,
            children: [
              ZsText(
                title,
                fontSize: 18,
                fontWeight: FontWeight.bold,
              ),
              rightChildr
            ],
          ),
          childr,
        ],
      ),
    );
  }

  @override
  void dispose() {
    super.dispose();
  }

  @override
  void initState() {
    super.initState();
    scrollController = ScrollController();
    if (ZsMemeryCache.loginDataModel?.userInfo?.companyId == COM_YM) {
      controller.roleLawcase();
    }
    controller.loginWork();
    initData();
  }

  @override
  bool get wantKeepAlive => true;

  void routeNative(String key, {String? name}) {
    switch (key) {
      case '送审专家':
        Get.to(ZsMineAuditPage(type: 0, index: 0));
        // routeNative('我的送审-查看更多');
        break;
      case '专家审核':
        Get.to(ZsMineAuditPage(type: 1, index: 0));
        // routeNative('我的审核-查看更多');
        break;
      case '我的任务':
        if (controller.projectDetail.value.pid == null ||
            controller.projectDetail.value.pid == '') {
          EasyLoading.showToast('项目数据正在加载，请稍后操作');
        }
        Get.to(() => ZsMoreTaskPage(), arguments: {
          'mineTask': true,
          'projectId': controller.projectDetail.value.pid,
          'projectType': controller.projectDetail.value.projectTypeId,
          'projectName': controller.projectDetail.value.projectName
        });
        break;
      case '项目任务':
        if (controller.projectDetail.value.pid == null ||
            controller.projectDetail.value.pid == '') {
          EasyLoading.showToast('项目数据正在加载，请稍后操作');
        }
        Get.to(() => ZsMoreTaskPage(), arguments: {
          'mineTask': false,
          'projectId': controller.projectDetail.value.pid,
          'projectType': controller.projectDetail.value.projectTypeId,
          'projectName': controller.projectDetail.value.projectName
        });
        break;
      case '项目人员':
        print('点击了');
        if (controller.projectDetail.value.pid == null ||
            controller.projectDetail.value.pid == '') {
          EasyLoading.showToast('项目数据正在加载，请稍后操作');
        }
        ProjectPersonnelView.push(
            projectTypeId: controller.projectDetail.value.projectTypeId);
        break;
      case '参与任务':
        if (controller.projectDetail.value.pid == null ||
            controller.projectDetail.value.pid == '') {
          EasyLoading.showToast('项目数据正在加载，请稍后操作');
        }
        Get.to(() => ZsTaskPartListPage(), arguments: {
          'projectId': controller.projectDetail.value.pid,
          'projectType': controller.projectDetail.value.projectTypeId,
          'projectName': controller.projectDetail.value.projectName
        });
        break;
      case '我的知会': //5:协同任务  7：我的知会  6：协同审批
        if (controller.projectDetail.value.pid == null ||
            controller.projectDetail.value.pid == '') {
          EasyLoading.showToast('项目数据正在加载，请稍后操作');
        }
        Get.to(() => ZsCotaskingListPage(), arguments: {
          'projectId': controller.projectDetail.value.pid,
          'projectName': controller.projectDetail.value.projectName,
          'type': 7
        });
        break;
      case '协同审批': //5:协同任务  7：我的知会  6：协同审批
        if (controller.projectDetail.value.pid == null ||
            controller.projectDetail.value.pid == '') {
          EasyLoading.showToast('项目数据正在加载，请稍后操作');
        }
        Get.to(() => ZsCotaskingListPage(), arguments: {
          'projectId': controller.projectDetail.value.pid,
          'projectName': controller.projectDetail.value.projectName,
          'type': 6
        });
        break;
      case '协同任务': //5:协同任务  7：我的知会  6：协同审批
        if (controller.projectDetail.value.pid == null ||
            controller.projectDetail.value.pid == '') {
          EasyLoading.showToast('项目数据正在加载，请稍后操作');
        }
        Get.to(() => ZsCotaskingListPage(), arguments: {
          'projectId': controller.projectDetail.value.pid,
          'projectName': controller.projectDetail.value.projectName,
          'type': 5
        });
        break;
      case '单位工程':
        if (controller.projectDetail.value.pid == null ||
            controller.projectDetail.value.pid == '') {
          EasyLoading.showToast('项目数据正在加载，请稍后操作');
        }
        Get.to(() => ZsProjectUnitConstructionPage(), arguments: {
          'projectType': controller.projectDetail.value.projectTypeId,
          'projectId': controller.projectDetail.value.pid,
        });
        break;
      case '日常工作':
        if (controller.projectDetail.value.pid == null ||
            controller.projectDetail.value.pid == '') {
          EasyLoading.showToast('项目数据正在加载，请稍后操作');
        }
        final Map<String, String> params = {
          'projectId': controller.projectDetail.value.pid ?? '',
          'projectName': controller.projectDetail.value.projectName ?? '',
          'projectStatus':
              controller.projectDetail.value.status.toString() ?? '',
          'standardProjectType':
              controller.projectDetail.value.projectTypeId ?? '',
          'projectCode': controller.projectDetail.value.projectCode ?? '',
          'projectTypeName': controller.projectDetail.value.projectType ?? '',
          'industryNatureOne':
              controller.projectDetail.value.industryNatureOne ?? '',
          'companyId': controller.projectDetail.value.companyId ?? '',
        };

        Get.toNamed(ZsRouter.zsWorkDailyMainPage, arguments: params);
        break;
      case '问题清单':
        if (controller.projectDetail.value.pid == null ||
            controller.projectDetail.value.pid == '') {
          EasyLoading.showToast('项目数据正在加载，请稍后操作');
        }
        Get.to(ZsProblemsPage(),
            arguments: {'projectId': controller.projectDetail.value.pid ?? ''});
        break;
      case '我的审核':
        ZsApprovalPage.push();
        break;
      case '工作动态':
        if (controller.projectDetail.value.pid == null ||
            controller.projectDetail.value.pid == '') {
          EasyLoading.showToast('项目数据正在加载，请稍后操作');
        }
        Get.to(WorkStatePage(
          projectId: controller.projectDetail.value.pid ?? '',
        ));
        break;
      case '项目自查':
        if (controller.projectDetail.value.pid == null ||
            controller.projectDetail.value.pid == '') {
          EasyLoading.showToast('项目数据正在加载，请稍后操作');
        }
        Get.to(() => ZsCheckingPage(0), arguments: {
          'projectType': controller.projectDetail.value.projectTypeId,
          'projectId': controller.projectDetail.value.pid
        });
        break;
      case '公司检查':
        if (controller.projectDetail.value.pid == null ||
            controller.projectDetail.value.pid == '') {
          EasyLoading.showToast('项目数据正在加载，请稍后操作');
        }
        Get.to(() => ZsCheckingPage(1), arguments: {
          'projectType': controller.projectDetail.value.projectTypeId,
          'projectId': controller.projectDetail.value.pid
        });
        break;
      case '整改通知':
        if (controller.projectDetail.value.pid == null ||
            controller.projectDetail.value.pid == '') {
          EasyLoading.showToast('项目数据正在加载，请稍后操作');
        }
        Get.to(() => ZsCorrectionNoticePage(), arguments: {
          'projectType': controller.projectDetail.value.projectTypeId,
          'projectId': controller.projectDetail.value.pid,
          'checkId': ''
        });
        break;
      case '乐捐通知':
        if (controller.projectDetail.value.pid == null ||
            controller.projectDetail.value.pid == '') {
          EasyLoading.showToast('项目数据正在加载，请稍后操作');
        }
        Get.to(() => ZsPenaltyNoticePage(), arguments: {
          'projectType': controller.projectDetail.value.projectTypeId,
          'projectId': controller.projectDetail.value.pid,
          'checkId': ''
        });
        break;
      case '线下工作':
        if (controller.projectDetail.value.pid == null ||
            controller.projectDetail.value.pid == '') {
          EasyLoading.showToast('项目数据正在加载，请稍后操作');
        }
        HYWorkOfflineListPage.push(arguments: {
          'projectType': controller.projectDetail.value.projectTypeId ?? '',
          'projectId': controller.projectDetail.value.pid ?? '',
          'projectName': controller.projectDetail.value.projectName ?? '',
          'checkId': ''
        });
        break;
      case '项目公告':
        WorkProjectAnnouncementListView.push();
        break;
      case '晴雨表':
        if (controller.projectDetail.value.pid == null ||
            controller.projectDetail.value.pid == '') {
          EasyLoading.showToast('项目数据正在加载，请稍后操作');
        }
        WorkProjectBarometerPage.push(
            projectId: controller.projectDetail.value.pid ?? '');
        break;
      case '合同管理':
        if (controller.projectDetail.value.pid == null ||
            controller.projectDetail.value.pid == '') {
          EasyLoading.showToast('项目数据正在加载，请稍后操作');
        }
        XMContractManagementView.push(
          projectId: controller.projectDetail.value.pid ?? '',
        );
        break;
      case '投资控制':
        XMInvestmentManagementView.push();
        break;
      case '进度控制':
        print('点击了进度控制');
        XMProgressControlView.push();
        break;
      case '项目资料':
        if (controller.projectDetail.value.pid == null ||
            controller.projectDetail.value.pid == '') {
          EasyLoading.showToast('项目数据正在加载，请稍后操作');
        }
        Get.to(() => ZsCommandProjectDataPage(),
            arguments: controller.projectDetail.value.pid);
        break;
      case '水印相机':
        if (Platform.isIOS) {
          if (controller.projectDetail.value.pid == null ||
              controller.projectDetail.value.pid == '') {
            EasyLoading.showToast('项目数据正在加载，请稍后操作');
          }
          methodChannel.invokeMethod(
              key, controller.projectDetail.value.toJson());
        } else {
          methodChannel.invokeMethod('OpenCamera', false);
        }
        break;
      case 'AI数钢筋':
        RebarDetectionPage.open();
        break;
      case '管理':
        HyWorkSettingPage.push(controller.itemList)?.then((value) {
          if (value is List<ItemModel>) {
            controller.itemList.value = value;
            controller.onUpdateLike();
          }
        });
        break;
      case '添加常用':
      case '添加':
        HYAddOftenUsedPage.push()?.then((dynamic value) {
          print('返回了');
          controller.onAllData();
        });
        break;
      case '我的签名':
        Get.to(ZsSignaturePage());
        break;
      case '考勤打卡':
        controller.routeMethod(key, '');
        break;
      case '考勤统计':
        Get.to(ClockInUserListPage());
        break;
      case '日志管理':
        Get.to(ZsWorkLogHomePage());
        break;
      case '我的邮件':
        Get.toNamed(ZsRouter.zsWorkEmailRouter);
        break;
      case '文档中心':
        WorkDocumentCenterView.push('', name ?? key, addRight: false);
        break;
      case '诉讼案件':
        LitigationCaseView.push();
        break;
      case '客户管理':
        Get.to(ZsCustomerManagementPage());
        break;
      case '图纸管理':
        HyDrawingManagementPage.push(
          projectId: controller.projectDetail.value.pid ?? '',
        );
        break;
      case '会议管理':
        HyMettingManagementPage.push();
        break;
      default:
        if (Platform.isIOS) {
          if (controller.projectDetail.value.pid == null ||
              controller.projectDetail.value.pid == '') {
            EasyLoading.showToast('项目数据正在加载，请稍后操作');
          }
          methodChannel.invokeMethod(
              key, controller.projectDetail.value.toJson());
        } else {
          if (controller.projectDetail.value.pid == null ||
              controller.projectDetail.value.pid == '') {
            EasyLoading.showToast('项目数据正在加载，请稍后操作');
          }
          final Map<String, dynamic> map = {
            'projectId': controller.projectDetail.value.pid,
            'createUser': controller.projectDetail.value.createUser,
            'projectName': controller.projectDetail.value.projectName,
            'projectStatus': controller.projectDetail.value.status,
            'projectTypeName': controller.projectDetail.value.projectType,
            'projectType': controller.projectDetail.value.projectTypeId,
            'projectCode': controller.projectDetail.value.projectCode
          };
          methodChannel.invokeMethod(key, map);
        }
        break;
    }
  }
}
